# auto_publish/models.py
from django.db import models
from django.contrib.auth.models import User


class VideoPublishTask(models.Model):
    STATUS_CHOICES = [
        ('pending', '待处理'),
        ('downloading', '下载中'),
        ('publishing', '发布中'),
        ('success', '发布成功'),
        ('failed', '发布失败'),
    ]

    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    video_url = models.URLField(verbose_name='视频URL')
    title = models.CharField(max_length=200, verbose_name='标题')
    description = models.TextField(blank=True, verbose_name='描述')
    tags = models.JSONField(default=list, verbose_name='标签')
    save_path = models.CharField(max_length=500, blank=True, verbose_name='保存路径')
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending', verbose_name='状态')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')

    class Meta:
        verbose_name = '视频发布任务'
        verbose_name_plural = '视频发布任务'

    def __str__(self):
        return f"{self.title} - {self.status}"
